<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>非父子组件传参</h2>
      <child1 @getcount="fn"></child1>
      <child2 :count="count"></child2>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child1 = {
        data() {
          return {
            count: 10,
          };
        },
        template: `
          <div>child1组件 - {{ count }}</div>
        `,
        mounted() {
          this.$emit("getcount", this.count);
        },
      };

      const Child2 = {
        props: ["count"],
        template: `
          <div>child2组件 - {{ count }}</div>
        `,
      };

      createApp({
        data() {
          return {
            count: 0,
          };
        },
        components: {
          Child1,
          Child2,
        },
        methods: {
          fn(c) {
            console.log("fn", c);
            this.count = c;
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
